package com.asurplus.business.controller;


import com.asurplus.business.entity.AppVersion;
import com.asurplus.business.service.AppVersionService;
import com.asurplus.common.layui.LayuiTableResult;
import com.asurplus.common.utils.ResponseResult;
import com.asurplus.system.service.SysDictDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * app版本信息 前端控制器
 * </p>
 *
 * @author lizhou
 * @since 2021-01-01
 */
@Controller
@RequestMapping("/business/app-version")
public class AppVersionController {

    @Autowired
    private AppVersionService appVersionService;
    @Autowired
    private SysDictDetailService sysDictDetailService;

    @GetMapping("init")
    public String init(Model model) {
        model.addAttribute("update", sysDictDetailService.listSysDictDetailByDictCode("app_force_update"));
        return "business/appversion/list";
    }

    @GetMapping("add")
    public String add(Model model) {
        model.addAttribute("update", sysDictDetailService.listSysDictDetailByDictCode("app_force_update"));
        return "business/appversion/add";
    }

    @GetMapping("update/{id}")
    public String update(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("data", appVersionService.getById(id));
        model.addAttribute("update", sysDictDetailService.listSysDictDetailByDictCode("app_force_update"));
        return "business/appversion/update";
    }

    @PostMapping("list")
    @ResponseBody
    public LayuiTableResult list(Integer page, Integer limit, AppVersion appVersion) {
        return appVersionService.list(page, limit, appVersion);
    }

    @PostMapping("add")
    @ResponseBody
    public ResponseResult add(@RequestBody AppVersion appVersion) {
        return appVersionService.add(appVersion);
    }

    @PostMapping("update")
    @ResponseBody
    public ResponseResult update(@RequestBody AppVersion appVersion) {
        return appVersionService.update(appVersion);
    }

    @GetMapping("del/{id}")
    @ResponseBody
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return appVersionService.delete(id);
    }

}
